﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2013/7/22 星期一 20:18:13
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Sector7.Framework.Enums;
using System.Windows;
using Sector7.Framework.Core;

namespace Sector7.Medical.Controls
{
    /// <summary>
    /// 概要信息控件基类
    /// </summary>
    public class SummaryControlBase : AddModeControlBase
    {
        #region Accessor
        #endregion

        #region Public functions
        #endregion

        #region Private functions
        /// <summary>
        /// 切换编辑按钮状态
        /// </summary>
        /// <param name="crud"></param>
        protected void SwitchEditableButtonsStatus(CrudType crud)
        {
            switch (crud)
            {
                case CrudType.Create:
                    m_btnModify.IsEnabled = false;
                    m_btnDelete.IsEnabled = false;
                    break;
                case CrudType.Read:
                    m_btnModify.IsEnabled = true;
                    m_btnDelete.IsEnabled = true;
                    break;
                default:
                    m_btnAdd.IsEnabled = false;
                    m_btnModify.IsEnabled = false;
                    m_btnDelete.IsEnabled = false;
                    break;
            }
        }

        /// <summary>
        /// 切换动作按钮状态
        /// </summary>
        /// <param name="isEditing"></param>
        protected void SwitchActionButtonStatus(bool isEditing)
        {
            m_btnOk.IsEnabled = isEditing;
            m_btnCancel.IsEnabled = isEditing;
        }

        /// <summary>
        /// 切换详细信息控件状态
        /// </summary>
        /// <param name="crud"></param>
        protected virtual void SwitchDetailControlsStatus(CrudType crud)
        {
        }

        /// <summary>
        /// 设置详细信息控件
        /// </summary>
        /// <param name="entity"></param>
        protected virtual void SetDetailControls(object entity)
        {
        }

        /// <summary>
        /// 重置详细信息控件
        /// </summary>
        protected virtual void ResetDetailControls()
        {
        }
                
        protected virtual void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (!m_isEdting)
            {
                m_isEdting = true;
                SwitchActionButtonStatus(m_isEdting);
                SwitchDetailControlsStatus(CrudType.Create);
            }
        }

        protected virtual void btnModify_Click(object sender, RoutedEventArgs e)
        {
            if (!m_isEdting)
            {
                m_isEdting = true;
                SwitchActionButtonStatus(m_isEdting);
                SwitchDetailControlsStatus(CrudType.Update);
            }
        }

        protected virtual void btnDelete_Click(object sender, RoutedEventArgs e)
        {
        }

        protected override void btnOk_Click(object sender, RoutedEventArgs e)
        {
            base.btnOk_Click(sender, e);

            if (m_isEdting)
            {
                m_isEdting = false;
                SwitchActionButtonStatus(m_isEdting);
                SwitchDetailControlsStatus(CrudType.Read);
            }
        }

        protected override void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            base.btnCancel_Click(sender, e);

            if (m_isEdting)
            {
                m_isEdting = false;
                SwitchActionButtonStatus(m_isEdting);
                SwitchDetailControlsStatus(CrudType.Read);
            }
        }
        #endregion

        #region Structure
        #endregion

        #region Inner members
        protected bool m_isEdting = false;
        protected Button m_btnAdd = null;
        protected Button m_btnModify = null;
        protected Button m_btnDelete = null;
        protected Button m_btnOk = null;
        protected Button m_btnCancel = null;
        #endregion
    }
}
